use actix_web::{web, App, HttpServer};
use router::router_rigster::router_rigster::config_routes_all;
mod controller;
mod router;
mod types;
mod common;
mod test;

use pkg::dbclient::db_config::MysqlConfig;
use pkg::establish_connection;

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let config: MysqlConfig = MysqlConfig { host: "127.0.0.1".to_string(), port: 3306, user: "root".to_string(), password: "root".to_string(), dbname: "pay_sdk".to_string() };
    let db= establish_connection(config).await;
    let db_data = web::Data::new(db);
    HttpServer::new(move || {
        let app = App::new();

        // 使用路由模块中的 config_routes 函数来配置所有路由
        app.app_data(db_data.clone()).configure(config_routes_all)
    })
        .bind(("127.0.0.1", 8989))?
        .run()
        .await
}